package com.example.demo;

import com.example.demo.config.BlogProperties;
import com.example.demo.config.BlogSpringProperties;
import com.example.demo.config.MyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@EnableConfigurationProperties({BlogSpringProperties.class, MyProperties.class})
//@ImportResource({"classpath:some-application.xml"})
public class DemoApplication {

    @Autowired
    private BlogProperties blogProperties;

    @Autowired
    private BlogSpringProperties blogSpringProperties;

    @Autowired
    private MyProperties myProperties;

    @RequestMapping("/")
    public String index(){
        return "hello springboot";
    }

    @RequestMapping("/agrs")
    public String args(){
        return blogProperties.toString();
    }

    @RequestMapping("/springArgs")
    public String springArgs(){
        return blogSpringProperties.toString();
    }

    @RequestMapping("/myArgs")
    public String myArgs(){
        return myProperties.toString();
    }

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(DemoApplication.class);
        app.setAddCommandLineProperties(false);  // 不允许命令行修改参数
        app.run(args);
    }

}
